package com.kfyty.loveqq.framework.boot.web.example.config;

import com.kfyty.loveqq.framework.core.autoconfig.annotation.Component;
import com.kfyty.loveqq.framework.web.core.http.ServerRequest;
import com.kfyty.loveqq.framework.web.core.http.ServerResponse;
import com.kfyty.loveqq.framework.web.core.interceptor.HandlerInterceptor;
import com.kfyty.loveqq.framework.web.core.mapping.Route;
import lombok.extern.slf4j.Slf4j;

/**
 * 描述: 响应式拦截器
 *
 * @author kfyty725
 * @date 2024/8/2 17:07
 * @email kfyty725@hotmail.com
 */
@Slf4j
@Component
public class LogHandlerInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(ServerRequest request, ServerResponse response, Route handler) {
        log.info("preHandleAsync: {}", request.getRequestURI());
        return true;
    }

    @Override
    public void postHandle(ServerRequest request, ServerResponse response, Route handler, Object retValue) {
        log.info("postHandleAsync: {} {}", request.getRequestURI(), retValue);
    }

    @Override
    public void afterCompletion(ServerRequest request, ServerResponse response, Route handler, Throwable ex) {
        log.info("afterCompletionAsync: {}", request.getRequestURI(), ex);
    }
}
